(function($, document, window) {
  'use strict';

 var ns = jfJQMAmobeeAds;

 function onClickOpenChildbrowser(e) {
   var $this = $(this);
   var url = $this.attr('href');
   if (!url.match(/^http/)) {
     return;
   }

   e.stopImmediatePropagation();
   e.preventDefault();

   window.open(url, '_blank', 'location=yes');

   return false;
 }
 
 if (window.cordova || window.PhoneGap) {

   document.addEventListener('deviceready', function() {

    $('body').delegate('.jfJQMAmobeeAd a[href]', 'click', onClickOpenChildbrowser);
    
    //hide/show native tabbar when interstitial is shown/hidden
    if (window.plugins && window.plugins.nativeControls) {
      var nsShowInterstitial = ns.showInterstitial;
      ns.showInterstitial = function($interstitial) {
        window.plugins.nativeControls.hideTabBar();
        var result = nsShowInterstitial($interstitial);        
        return result;
      };
      
      var nsHideInterstitial = ns.hideInterstitial;
      ns.hideInterstitial = function($interstitial, timeout, immediately) {
        var result = nsHideInterstitial($interstitial, timeout, immediately);        
        window.plugins.nativeControls.showTabBar();
        return result;
      };
    }

     
   }, false);
 }

})(window.jQuery, document, window);